//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.lyq.bean.mySql;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class PlusResidueNum_Sql {
    public PlusResidueNum_Sql() {
    }

    public Boolean plusResidueNum_Sql(String cNo) {
        (new MysqlLinking()).getLink();
        Connection conn = MysqlLinking.conn;
        Boolean bool = false;
        if (conn != null) {
            try {
                String sql = "select * from course where C_No=?";
                PreparedStatement ps = conn.prepareStatement(sql);
                ps.setString(1, cNo);
                ResultSet rs = ps.executeQuery();

                int residueNum;
                for(residueNum = 0; rs.next(); residueNum = Integer.valueOf(rs.getString("C_ResidueNum"))) {
                }

                // 移除了对residueNum <= 30的限制，允许任何有效的课程剩余人数增加
                if (residueNum >= 0) {
                    try {
                        String sql_2 = "update  course set C_ResidueNum=?  where C_No=?";
                        PreparedStatement ps_2 = conn.prepareStatement(sql_2);
                        int re = residueNum + 1;
                        ps_2.setString(1, String.valueOf(re));
                        ps_2.setString(2, cNo);
                        int count = ps_2.executeUpdate();
                        if (count >= 1) {
                            bool = true;
                        }
                    } catch (Exception var12) {
                        Exception e = var12;
                        e.printStackTrace();
                    }
                }
            } catch (Exception var13) {
                Exception e = var13;
                e.printStackTrace();
            }
        } else {
            System.out.println("数据库连接错误！");
        }

        return bool;
    }
}